<template>
  <div>
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="pyjm" label="" class="ml-2">
          <a-input v-model:value="formState.pyjm" class="w-64" placeholder="姓名/助记码/住院号" @keydown.enter="getData" />
        </a-form-item>
        <a-form-item name="dateRange" label="创建日期" class="!w-[300px] ml-3">
          <a-range-picker v-model:value="formState.dateRange" arrow-point-at-center allow-clear format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2">
      <div class="flex justify-end">
        <a-button class="mb-2"> 导出 </a-button>
      </div>
      <BaseTable fill :data-source="tableData" :loading="loading" :scroll="{ x: 1800 }" column-code="000089" :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'no'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'whetherInsured'">
            <!-- 是否医保登记 1:医保登记 -->
            <a-tag v-if="record.whetherInsured === 1" color="purple">医保</a-tag>
            <a-tag v-else color="blue">自费</a-tag>
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-space>
              <a-button type="link" size="small" @click="openEditModel(record)">修改</a-button>
            </a-space>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <InpatientInfo v-model:open="editModelOpen" :row-data="rowData" title="患者档案修改" @success="onEditSuccess" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SearchContainer from '@/components/SearchContainer'
import InpatientInfo from '@/components/InpatientInfo'

const rowData = ref(null)
const formRef = ref(null)
const editModelOpen = ref(false)
const formState = ref({
  dateRange: [],
  pyjm: ''
})
const { loading, tableData, pagination, getData } = useTable({
  url: '/inp/zydj/getInpPatientFiles',
  immediate: true,
  params: formState.value
})

const openEditModel = (val) => {
  rowData.value = val
  editModelOpen.value = true
}
const onEditSuccess = () => {
  rowData.value = {}
  getData()
}
</script>
